const path = require('path');
const fs = require('fs');

const serviceFactory = (() => {
    let obj = {};
    let arr = fs.readdirSync(path.join(__dirname,"../services"));
    //['AdminInfoService.js','BaseService.js','RoomInfoService.js','StuInfoService.js']
    //构建属性名
    for(let item of arr){
        let propertyName = item.replace(".js","").replace(/^[A-Z]/,p => p.toLowerCase());
        let temp = require(path.join(__dirname,'../services',item));
        // node/service/AdminInfoService.js
        if(typeof temp === "function"){
            obj[propertyName] = Reflect.construct(temp,[]);
        }
    }
    console.log('service',obj);
    
    return obj;
})()

module.exports = serviceFactory;